import request from '@/utils/request'

export const createChat = (data: {
  query: string
  userName: string
  responseMode: 'streaming' | 'blocking'
  inputs?: any
  conversationId?: string
}) => {
  return request.post('/dify/createScheme', { data })
}

// 预制话术
export const getPreset = () => {
  return request.get('/phrases/getPhrases')
}

// 获取agent信息
export const getAgentInfo = (params?: { id: string }) => {
  return request.get('/agentManage/getAgentInfo', { params })
}

// 首页对话接口
export const getHomeChat = (data: {
  query: string
  userName: string
  responseMode: 'streaming' | 'blocking'
  inputs?: any
  conversationId?: string
}) => {
  return request.post('/dify/agentChat', { data })
}

// 反馈
export const feedback = (data: { messageId: string; user: string; rating: string }) => {
  return request.post('/dify/feedback', { data })
}

// 历史记录
export const getHistory = (data: {
  user: string
  limit: number
  sort_by?: string
  last_id?: string
}) => {
  return request.post('/dify/getConversationList', { data })
}

// 会话重命名
export const renameConversation = (params: { conversation_id: string; name: string }) => {
  return request.post('/dify/updateConversationName', { params })
}

// 会话历史记录
export const getConversationHistory = (params: {
  conversation_id: string
  limit: number
  first_id?: string
  name?: string
}) => {
  return request.get('/dify/getConversationHistory', { params })
}

// 删除会话
export const deleteConversation = (params: { conversation_id: string; name: string }) => {
  return request.post('/dify/deleteConversation', { params })
}

// 创建浏览记录
export const createBrowseRecord = (data: {
  agentId: string
  userId: string
  accessTime: string
}) => {
  return request.post('/agent/visits/create', { data })
}

// 创建体验记录
export const createExperienceRecord = (data: {
  agentId: string
  userId: string
  accessTime: string
  referrer: string
}) => {
  return request.post('/agent/experience/create', { data })
}

// 点赞点踩
export const likeOrDislike = (data: {
  agentId: string
  userId: string
  interactionType: 1 | 2 | 3 | 4 // 1 点赞 2 点踩 3 取消赞 4 取消踩
}) => {
  return request.post('/interaction/records/create', { data })
}

// 获取当前用户点赞点踩记录
export const getUserInteractionRecords = (params: { agentId: string; userId: string }) => {
  return request.get('/interaction/records/get', { params })
}
